/**
 * Copyright 2014-2016 eyaomall.com 
 * All rights reserved.
 * 
 * @project
 * @author jackey
 * @version 1.0
 * @date 2015-09-11
 */
package com.eyaomall.wxmanage.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.eyaomall.wxmanage.dao.ResourceDao;
import com.eyaomall.wxmanage.model.po.Resource;
import com.eyaomall.wxmanage.service.ResourceService;
import com.lycheeframework.core.common.util.StringUtil;
@Service
public class ResourceServiceImpl implements ResourceService {

	@Autowired
	private ResourceDao resourceDao;
	
	public Resource getOption(int id) {
		if (id <=0) return null;
		
		return resourceDao.query(id);
	}

	@SuppressWarnings("unchecked")
	public List<Resource> getOptions(String resourceKey) {
		if (StringUtil.isEmpty(resourceKey)) return null;
		
		Resource resource = new Resource();
		resource.setResourceKey(resourceKey);
		
		return resourceDao.list(resource);
	}

	@SuppressWarnings("unchecked")
	public List<Resource> getOptions(String resourceKey, int parentId) {
		if (StringUtil.isEmpty(resourceKey) || parentId <=0) return null;
		
		Resource resource = new Resource();
		resource.setResourceKey(resourceKey);
		resource.setParentId(parentId);
		
		return resourceDao.list(resource);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Resource> getOptions(int parentId) {
		if (parentId <=0) return null;
		
		Resource resource = new Resource();
		resource.setParentId(parentId);
		
		return resourceDao.list(resource);
	}
	
	/**
	 * 返回所有资源信息
	 */
	@SuppressWarnings("unchecked")
	public List<Resource> getResources(){
		
		return resourceDao.list("selectAllResources", null);
	}
}
